/*
 * @Author: Zhouwei
 * @Date: 2022-08-25 16:37:04
 * @LastEditors: Zhouwei
 * @LastEditTime: 2022-08-26 17:40:56
 * @Description:
 */
const axios = require('axios')
const config = require('./config')
module.exports = {
  //获取天气
  getWeather: () => {
    return new Promise((resolve, reject) => {
      // let data;
      axios({
        methods: 'post',
        url: 'http://api.tianapi.com/tianqi/index',
        params: {
          key: config.tianXin.key,
          city: config.users.city,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist[1]) //今天的天气，0是昨天 2是明天
          } else {
            reject(res.data)
          }
        })
        .catch((err) => {
          reject(error)
        })
    })
  },
  //健康小提示
  getHealthtip: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'post',
        url: 'http://api.tianapi.com/healthtip/index',
        params: {
          key: config.tianXin.key,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist[0])
          } else {
            reject(res.data)
          }
        })
        .catch((err) => {
          reject(error)
        })
    })
  },
  // 励志古言
  getLzmy: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'post',
        url: 'http://api.tianapi.com/lzmy/index',
        params: {
          key: config.tianXin.key,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist[0])
          } else {
            reject(res.data)
          }
        })
        .catch((err) => {
          reject(error)
        })
    })
  },
  //   早安语
  getzaoan: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'get',
        url: 'http://api.tianapi.com/zaoan/index',
        params: {
          key: config.tianXin.key,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist[0])
          } else {
            reject(res.data)
          }
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 星座
  getxinzuo: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'get',
        url: 'http://api.tianapi.com/star/index',
        params: {
          key: config.tianXin.key,
          astro: config.users.star,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist)
          } else {
            reject(res.data)
          }
        })
        .catch((error) => {
          reject(error)
        })
    })
  },

  //   中午发送的
  //   天狗日记名言
  gettiangou: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'get',
        url: 'http://api.tianapi.com/tiangou/index',
        params: {
          key: config.tianXin.key,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist[0])
          } else {
            reject(res.data)
          }
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  //   热搜吃瓜
  getchigua: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'post',
        url: 'http://api.tianapi.com/weibohot/index',
        params: {
          key: config.tianXin.key,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist)
          } else {
            reject(res.data)
          }
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  //   鸡汤来喽
  getjitang: () => {
    return new Promise((resolve, reject) => {
      axios({
        methods: 'post',
        url: 'http://api.tianapi.com/dujitang/index',
        params: {
          key: config.tianXin.key,
        },
      })
        .then((res) => {
          if (res.data.code == 200) {
            resolve(res.data.newslist[0])
          } else {
            reject(res.data)
          }
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}
